<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('index')}">{:lang('DATACENTER')}</a></li>
        <li><a href="{:url('edit')}">{:lang('DATACENTER_ADD')}</a></li>
    </ul>
    <form id="syncForm" class="well form-inline margin-top-20" method="post" action="{:url('sync')}">
            服务器地址IP/URL
            <input type="text" class="form-control" name="server_url" id="server_url" style="width: 220px;" placeholder="服务器地址IP/URL">
            <input type="button" class="btn btn-primary" value="同步" onclick="sync()"/>
            <a class="btn btn-danger" href="{:url('index')}">清空</a>
    </form>
    <table class="table table-hover table-bordered table-list">
        <thead>
        <tr>
            <th width="50">选择</th>
            <th width="50">ID</th>
            <th width="50">KEY</th>
            <th width="50">配置名称</th>
            <th width="50">配置类型</th>
            <th width="50">备注</th>
            <th width="60">添加时间</th> 
            <th width="20">{:lang('ACTIONS')}</th>
        </tr>
        </thead>
        <tbody>
        <foreach name="items" item="vo">
            <tr>
                <td class="ckb"><input class="checkbox" type="checkbox" id="{$vo.id}" /></td>
                <td>{$vo.id}</td>
                <td>{$vo.key_m}</td>
                <td>{$vo.name_m}</td>
                <td>{$vo.type_n}</td>
                <td>{$vo.desc}</td>
                <td>{$vo.create_dt}</td>
                <td>
                    <a href="{:url('edit',array('id'=>$vo['id']))}">{:lang('EDIT')}</a>
                    <a href="{:url('delete',array('id'=>$vo['id']))}" class="js-ajax-delete">{:lang('DELETE')}</a>
                </td>
            </tr>
        </foreach>
        </tbody>
        <tfoot>
        <tr>
            <th width="50">选择</th>
            <th width="50">ID</th>
            <th width="50">KEY</th>
            <th width="50">配置名称</th>
            <th width="50">配置类型</th>
            <th width="50">备注</th>
            <th width="60">添加时间</th> 
            <th width="20">{:lang('ACTIONS')}</th>
        </tr>
        </tfoot>
    </table>
    <div class="pagination">{$page}</div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
    $('.ckb').bind('click',function(){
        var it = $(this).children('.checkbox');
       it.prop('checked',!it.prop('checked'));
    });
    function sync(){
        var url = $('#server_url').prop('value');
        if(!url || url.length<1){
            alert('请输入需要同步的服务器地址');
            return;
        }
        url = url.trim();
        var val = /([0-9]{1,3}\.{1}){3}[0-9]{1,3}/;
        var vald = val.exec(url);
        if (!vald) {
            alert('注意IP有效性');
            return false;
        }
        var ids = "";
        $('.checkbox').each(function(i,it){
            var item = $(it);
            if(item.prop('checked')){
                ids = ids+item.prop('id');
                item.prop('checked',false);
            }
        });
        if(ids.length<1){
            alert('请选择需要同步的数据');
            return;
        }
        $.post($('#syncForm').attr('action'),{'ids':ids,'url':url},function(data){
            alert(data.msg);
        });
    }
</script>
</body>
</html>